package com.ruoyi.lm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lm.domain.LmUserlevelpackage;
import com.ruoyi.lm.service.ILmUserlevelpackageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户套餐关联Controller
 * 
 * @author ruoyi
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/lm/userlevelpackage")
public class LmUserlevelpackageController extends BaseController
{
    private String prefix = "lm/userlevelpackage";

    @Autowired
    private ILmUserlevelpackageService lmUserlevelpackageService;

    @RequiresPermissions("lm:userlevelpackage:view")
    @GetMapping()
    public String userlevelpackage()
    {
        return prefix + "/userlevelpackage";
    }

    /**
     * 查询用户套餐关联列表
     */
    @RequiresPermissions("lm:userlevelpackage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LmUserlevelpackage lmUserlevelpackage)
    {
        startPage();
        List<LmUserlevelpackage> list = lmUserlevelpackageService.selectLmUserlevelpackageList(lmUserlevelpackage);
        return getDataTable(list);
    }

    /**
     * 导出用户套餐关联列表
     */
    @RequiresPermissions("lm:userlevelpackage:export")
    @Log(title = "用户套餐关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LmUserlevelpackage lmUserlevelpackage)
    {
        List<LmUserlevelpackage> list = lmUserlevelpackageService.selectLmUserlevelpackageList(lmUserlevelpackage);
        ExcelUtil<LmUserlevelpackage> util = new ExcelUtil<LmUserlevelpackage>(LmUserlevelpackage.class);
        return util.exportExcel(list, "userlevelpackage");
    }

    /**
     * 新增用户套餐关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 选择用户
     */
    @GetMapping("/chooseUser")
    public String chooseUser()
    {
        return prefix + "/user";
    }

    /**
     * 选择用户
     */
    @GetMapping("/choosePackage")
    public String choosePackage()
    {
        return prefix + "/levelpackage";
    }

    /**
     * 新增保存用户套餐关联
     */
    @RequiresPermissions("lm:userlevelpackage:add")
    @Log(title = "用户套餐关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LmUserlevelpackage lmUserlevelpackage)
    {
        return toAjax(lmUserlevelpackageService.insertLmUserlevelpackage(lmUserlevelpackage));
    }

    /**
     * 修改用户套餐关联
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        LmUserlevelpackage lmUserlevelpackage = lmUserlevelpackageService.selectLmUserlevelpackageById(id);
        mmap.put("lmUserlevelpackage", lmUserlevelpackage);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户套餐关联
     */
    @RequiresPermissions("lm:userlevelpackage:edit")
    @Log(title = "用户套餐关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LmUserlevelpackage lmUserlevelpackage)
    {
        return toAjax(lmUserlevelpackageService.updateLmUserlevelpackage(lmUserlevelpackage));
    }

    /**
     * 删除用户套餐关联
     */
    @RequiresPermissions("lm:userlevelpackage:remove")
    @Log(title = "用户套餐关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lmUserlevelpackageService.deleteLmUserlevelpackageByIds(ids));
    }
}
